home *** CD-ROM | disk | FTP | other *** search
- { IMPORTANT NOTE: This code is provided for illustrative purposes only, remember that
- you need to take these ideas and rework them for use in your own programs, in order
- to achieve adequate security }
-
- { Listing 1 }
-
- function DelphiIDERunning : Boolean;
- begin
- Result := FindWindow ('TAppBuilder', Nil) <> 0;
- if Result then Result := FindWindow ('TApplication', Nil) <> 0;
- if Result then Result := FindWindow ('TPropertyInspector', 'Object Inspector') <> 0;
- if Result then Result := FindWindow ('TProjectManager', 'Project Manager') <> 0;
- ---- etc ----
- end;
-
- { Listing 2 }
-
- function DelphiIDERunning: Boolean;
- type
- GetProcAddressType = function (hMod: hModule; FuncName: PChar): Pointer; stdcall;
- FindWindowType = function (ClassName, WndName: PChar): hWnd; stdcall;
- var
- modKernel, modUser: hModule;
- lpProcAddress: GetProcAddressType;
- lpFindWindow: FindWindowType;
- begin
- Result := False;
- modUser := GetModuleHandle ('USER32.DLL');
- if modUser <> 0 then begin
- modKernel := GetModuleHandle ('KERNEL32.DLL');
- if modKernel <> 0 then begin
- lpProcAddress := GetProcAddress (modKernel, 'GetProcAddress');
- if @lpProcAddress <> Nil then begin
- lpFindWindow := lpProcAddress (modUser, 'FindWindowA');
- if @lpFindWindow <> Nil then begin
- Result := lpFindWindow ('TAppBuilder', Nil) <> 0;
- end;
- end;
- end;
- end;
- end;
-
- { Listing 3 }
-
- const
- szUser32DLL: String = Chr(230)+Chr(230)+Chr(238)+Chr(132)+Chr(152)+Chr(153)+Chr(248)+
- Chr(239)+Chr(249)+Chr(255);
- szKernel32DLL: String = Chr(230)+Chr(230)+Chr(238)+Chr(132)+Chr(152)+Chr(153)+Chr(230)+
- Chr(239)+Chr(228)+Chr(248)+Chr(239)+Chr(225);
- szGetProcAddress: String = Chr(217)+Chr(217)+Chr(207)+Chr(216)+Chr(206)+Chr(206)+Chr(235)+
- Chr(201)+Chr(197)+Chr(216)+Chr(250)+Chr(222)+Chr(207)+Chr(237);
- szFindWindowA: String = Chr(235)+Chr(221)+Chr(197)+Chr(206)+Chr(196)+Chr(195)+Chr(253)+
- Chr(206)+Chr(196)+Chr(195)+Chr(236);
- szTAppBuilder: String = Chr(216)+Chr(207)+Chr(206)+Chr(198)+Chr(195)+Chr(223)+Chr(232)+
- Chr(218)+Chr(218)+Chr(235)+Chr(254);
-
- function MassageString (const S: String): String;
- var
- Idx: Integer;
- begin
- SetLength (Result, Length (S));
- for Idx := 0 to Length (S) - 1 do
- Result [Idx + 1] := Chr (Ord (S [Length (S) - Idx]) xor $AA);
- end;
-
- function DelphiIDERunning: Boolean;
- type
- GetProcAddressType = function (hMod: hModule; FuncName: PChar): Pointer; stdcall;
- FindWindowType = function (ClassName, WndName: PChar): hWnd; stdcall;
- var
- modKernel, modUser: hModule;
- lpProcAddress: GetProcAddressType;
- lpFindWindow: FindWindowType;
- begin
- Result := False;
- modUser := GetModuleHandle (PChar (MassageString (szUser32DLL)));
- if modUser <> 0 then begin
- modKernel := GetModuleHandle (PChar (MassageString (szKernel32DLL)));
- if modKernel <> 0 then begin
- lpProcAddress := GetProcAddress (modKernel, PChar (MassageString (szGetProcAddress)));
- if @lpProcAddress <> Nil then begin
- lpFindWindow := lpProcAddress (modUser, PChar (MassageString (szFindWindowA)));
- if @lpFindWindow <> Nil then begin
- Result := lpFindWindow (PChar (MassageString (szTAppBuilder)), Nil) <> 0;
- end;
- end;
- end;
- end;
- end;
-
-
- { Listing 4 }
-
- procedure MassageToClip (const S: String);
- var
- Idx: Integer;
- Str: String;
- begin
- for Idx := 1 to Length (S) do begin
- if Idx <> 1 then Str := Str + '+';
- Str := Str + Format ('Chr(%d)', [Ord (S [Idx])]);
- end;
-
- Clipboard.SetTextBuf (PChar (Str));
- end;
-
- { Listing 5 }
-
- procedure TMain.Refresh;
- var
- MoreToDo: Boolean;
- Snapshot: THandle;
- pe: TProcessEntry32;
- Node: TdxTreeListNode;
- begin
- TreeList.ClearNodes;
- TreeList.BeginUpdate;
-
- try
- Snapshot := CreateToolhelp32Snapshot (th32cs_SnapProcess, 0);
- try
- pe.dwSize := sizeof (pe);
- MoreToDo := Process32First (Snapshot, pe);
- while MoreToDo do begin
- Node := TreeList.Add;
- Node.Values [0] := ExtractFileName (StrPas (pe.szExeFile));
- Node.Values [1] := IntToHex (pe.th32ProcessID, 8);
- Node.Values [2] := pe.pcPriClassBase;
- Node.Values [3] := pe.cntThreads;
- Node.Values [4] := pe.dwFlags;
- Node.Values [5] := StrPas (pe.szExeFile);
- MoreToDo := Process32Next (Snapshot, pe);
- end;
- finally
- CloseHandle (Snapshot);
- end;
- finally
- TreeList.EndUpdate;
- SelNode := TreeList.TopNode;
- end;
- end;
-
-